from random import randint


def create_num():
    nums = []
    for i in range(6):
        # 生成一个球
        while True:
            num = randint(1, 32)
            if num not in nums:
                nums.append(num)
                break
        blue = randint(1, 15)
    nums = sorted(nums)
    nums.append(blue)
    return nums


def pan_duan(nums, buy_nums):
    red = 0
    blue = 0
    for i in buy_nums[:-1]:  # 判断红球中了多少个
        if i in nums[:-1]:
            red += 1
    if buy_nums[-1] == nums[-1]:  # 判断蓝球中了没有
        blue += 1

    print(f"中红色球{red}个")
    print(f"中蓝色球{blue}个")
    # 判断中了几等奖
    if red == 6 and blue == 1:
        return 1
    elif red == 6:
        return 2
    elif red == 5 and blue == 1:
        return 3
    elif (red == 5 and blue == 0) or (red == 4 and blue == 1):
        return 4
    elif (red == 4 and blue == 0) or (red == 3 and blue == 1):
        return 5
    elif (red == 2 and blue == 1) or (red == 1 and blue == 1) or (red == 0 and blue == 1):
        return 6
    else:
        return 0


create_num = create_num()
print(f"开奖号码：{create_num}")
buy_num = [1, 31, 24, 3, 3, 5, 2]
print(f"购买号码：{buy_num}")
print(f"您中了：{pan_duan(create_num, buy_num)}等奖")
